#ifndef IMAGEPROVIDER_H
#define IMAGEPROVIDER_H

#include <QObject>

#include <QHash>

class QNetworkAccessManager;
class QNetworkReply;
class QPixmap;

class RequestResponser : public QObject
{
    Q_OBJECT

    QString multiverId;

public:
    RequestResponser(QObject *parent, QString multiverId, QObject *receiver, const char *member)
        : QObject(parent), multiverId(multiverId)
    {
        QObject::connect(this, SIGNAL(pixmapReady(QPixmap)), receiver, member);
    }

public slots:
    void receivePixmap(const QString &multiverId, const QPixmap &pixmap)
    {
        if (this->multiverId == multiverId) {
            emit pixmapReady(pixmap);
            deleteLater();
        }
    }

signals:
    void pixmapReady(const QPixmap &pixmap);
};

class ImageProvider : public QObject
{
    Q_OBJECT

private:

    QNetworkAccessManager *manager;
public:
    explicit ImageProvider(QObject *parent = 0);

    void requestImage(const QString &multiverseId, QObject *receiver, const char *member);

    static ImageProvider &instance();

signals:
    void pixmapReady(QString multiverId, const QPixmap &pixmap);

private slots:
    void downloadFinished(QNetworkReply *reply);

};

#endif // IMAGEPROVIDER_H
